package com.lovo.frame;

import com.lovo.pojo.UserDO;
import com.lovo.util.Util;


import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class ATM extends JFrame {
    private ArrayList<UserDO> list;
    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private CardLayout cardLayout = new CardLayout();
    private OffPanel offPanel = new OffPanel(this);
    private SavePanel savePanel = new SavePanel(this);
    private GetPanel getPanel = new GetPanel(this);
    private FindPanel findPanell = new FindPanel(this);
    private Transfer transferPanell = new Transfer(this);
    private ChangeSecret changeSecretPanell = new ChangeSecret(this);
//    private Image bgImg = Util.getImage("/images/background.jpg");
    private UserDO loginUser;

    public UserDO getLoginUser() {
        return loginUser;
    }

    public FindPanel getFindPanell() {
        return findPanell;
    }

    public void setFindPanell(FindPanel findPanell) {
        this.findPanell = findPanell;
    }

    public ATM() {

//        this.setContentPane(new JPanel() {
//            @Override
//            protected void paintComponent(Graphics g) {
//                super.paintComponent(g);
//                g.drawImage(bgImg, 0, 0, 1024, 768, this);
//            }
//        });
        this.setLayout(cardLayout);
        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("off", offPanel);
        this.add("save", savePanel);
        this.add("get", getPanel);
        this.add("find", findPanell);
        this.add("gaimi", changeSecretPanell);
        this.add("zhuan", transferPanell);
        this.setSize(1024, 768);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

//    public void init() {
////        if (list == null) {
////            list = new ArrayList<>();
////            list.add(new User("zhangsan", "111111", 10000));
////            list.add(new User("lisi", "222222", 20000));
////            list.add(new User("wangwu", "333333", 30000));
////            list.add(new User("zhaoliu", "444444", 40000));
////            list.add(new User("heihei", "555555", 50000));
////        }
//        list=Util.query();
//    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }
    public void setLoginUser(UserDO loginUser) {
        this.loginUser = loginUser;
    }

    public static void main(String[] args) {
        new ATM();
    }

    public ArrayList<UserDO> getList() {
        return list;
    }

    public void setList(ArrayList<UserDO> list) {
        this.list = list;
    }

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }
}
